(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.ResponsesView = (function(_super) {

    __extends(ResponsesView, _super);

    function ResponsesView() {
      return ResponsesView.__super__.constructor.apply(this, arguments);
    }

    ResponsesView.prototype.initialize = function() {
      ResponsesView.__super__.initialize.apply(this, arguments);
      this.model.bind("change", this.render);
      return this.model.fetch();
    };

    ResponsesView.prototype.events = {
      "submit form.general": "addResponse",
      "click ul.comments li h2": "showProfile"
    };

    ResponsesView.prototype.render = function() {
      var _this = this;
      return this.GetTemplate(SiteMap.Responses.Template, function(compiledTemplate) {
        return $(_this.el).html(compiledTemplate(_this.model.toJSON()));
      });
    };

    ResponsesView.prototype.addResponse = function(event) {
      var data, form,
        _this = this;
      event.preventDefault();
      form = $("#responses").find("form");
      data = form.serialize();
      Messages.WriteMessage("Добавляется отзыв...");
      return $.post(SiteMap.Responses.Save, data, function(response) {
        if ((response.SuccessMessage != null) && response.SuccessMessage.length) {
          Messages.WriteMessage(response.SuccessMessage);
          return _this.model.fetch();
        } else {
          return Messages.WriteErrors(response.Errors);
        }
      });
    };

    ResponsesView.prototype.showProfile = function(e) {
      var login, url;
      e.preventDefault();
      login = $(e.target).html();
      if (login != null) {
        url = SiteMap.Account.ShowProfile + "/" + login;
        return this.Navigate(url, true);
      }
    };

    return ResponsesView;

  })(CustomView);

}).call(this);
